package com.lanou3g.demo.controller;

import com.lanou3g.demo.entity.AdminInfo;
import com.lanou3g.demo.entity.ModuleInfo;
import com.lanou3g.demo.service.ILoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;


@RestController
@RequestMapping("/admin")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    //    校验管理员用户
    @RequestMapping("/findOne1")
    public Boolean findOne1(
            String name,String password,String code, HttpServletRequest request){
//            @Validated AdminInfo info,
//                            String code, HttpServletRequest request) {
        System.out.println(code);
        HttpSession session = request.getSession();
        session.setAttribute("name", name);
        AdminInfo info = new AdminInfo();
        info.setName(name);
        info.setPassword(password);
        Boolean aBoolean = loginService.findOne1(info);
        System.out.println(aBoolean);
        if (aBoolean==true){
            return true;
        }
        return  false;
//        System.out.println(name+password+code);
//        return true;
    }

    //    查看权限显示模块
    @RequestMapping(value = "/findModule")
    public List<ModuleInfo> findModule(HttpServletRequest request) {
        HttpSession session = request.getSession();

        String name = (String) session.getAttribute("name");

        List<ModuleInfo> infoQxes = loginService.findModule(name);
        infoQxes.forEach(System.out::println);

        return infoQxes;
    }


}
